package com.net.xpay.common.domain;


import com.net.common.domain.CommonDomain;
import com.net.xpay.common.enums.systemTask.DailyTaskStatus;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 通用的按天执行的任务的记录.
 */
@Getter
@Setter
@NoArgsConstructor
public class DailyTaskRecord extends CommonDomain {
    private String taskName; //Ref:DailyTaskName

    private LocalDate day;   //执行的日期 2015/10/11 00:00:00

    private Integer isManualTask; //是否手工指定任务; 可以指定特定的日期任务(重跑). 1 代表手动任务

    private String taskStatus; //Ref:DailyTaskStatus

    private Long totalCount;   //总共处理的数量(比如店铺数量),自己定义含义

    private Long successCount; //处理成功的数量

    private Long failedCount; //处理失败的数量

    private Long processCount; //已处理的数量

    private LocalDateTime startTime; //任务开始时间

    private LocalDateTime endTime; //任务结束时间

    private String errorCode; //出错信息

    private String errorMessage; //出错信息

    private String ip; //在那台机器处理的

    public static DailyTaskRecord getInstance(String taskName, LocalDate day, Integer isManualTask, String ip) {
        DailyTaskRecord record = new DailyTaskRecord();
        record.setTaskName(taskName);
        record.setDay(day);
        record.setIsManualTask(isManualTask);
        record.setTaskStatus(DailyTaskStatus.START);
        record.setTotalCount(0L);
        record.setSuccessCount(0L);
        record.setFailedCount(0L);
        record.setProcessCount(0L);
        record.setStartTime(LocalDateTime.now());
        record.setIp(ip);

        return record;
    }
}
